package com.sdp.refund.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.sdp.core.bizc.vo.Result;
import com.sdp.refund.db.refund_notice.entity.RefundNotice;
import com.sdp.refund.db.refund_notice.service.IRefundNoticeService;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zsp
 * @since 2024-08-31
 */
@RestController
@RequestMapping("/RefundNoticeController")
public class RefundNoticeController {
	
	@Autowired
	private IRefundNoticeService iRefundNoticeService;
	
	@GetMapping(value = "/queryRefundNotice")
	public Result<?> queryRefundNotice() {
		LambdaQueryWrapper<RefundNotice> queryWrapper = new LambdaQueryWrapper<>();
		return Result.ok(iRefundNoticeService.getOne(queryWrapper));
	}
	
	
	@PostMapping(value = "/save")
	@Transactional(rollbackFor=Exception.class)
	public Result<?> save(@RequestBody RefundNotice notice) {
		if(notice==null) {
			return Result.error("公告信息为空");
		}
		if(StringUtils.isEmpty(notice.getKeyId())) {
			iRefundNoticeService.save(notice);
		}else {
			iRefundNoticeService.updateById(notice);
		}
		return Result.ok();
	}
}

